﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Management.BLL;
using Util.Webs.EasyUi.Trees;
using Util.Webs.EasyUi.Results;
using Management.Entity;

namespace MET.Web.Controllers
{
    public class ModulesController : Controller
    {
        //
        // GET: /Modules/

        public ActionResult Index()
        {
            
            return View();
        }
        public ActionResult GetAll()
        {
            ModuleService service = new ModuleService();
            var modulelist = service.GetAllModules();
            return Json(modulelist, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        [UIExceptionResult]
        public ActionResult Add(Module entity)
        {
            if(entity!=null&&!string.IsNullOrWhiteSpace(entity.ModuleName))
            {
            ModuleService service = new ModuleService();
            var result = service.Add(entity);
            if (result)
                return Content("OK");
            else
                return Content("ERROR");
            }
            else
                return Content("ERROR");
        }
        [UIExceptionResult]
        public ActionResult GetInfo(int id)
        {
            ModuleService service = new ModuleService();
            var V = service.GetModuleInfo(id);
            return Json(V, JsonRequestBehavior.AllowGet);
        }
         [HttpPost]
        public ActionResult Update(Module entity)
        {
            ModuleService service = new ModuleService();
            var v = service.Update(entity);
            if (v)
            {
                return Content("OK");
            }
            return Content("ERROR");
        }
         [HttpPost]
         public ActionResult Delete(int id)
         {
             ModuleService service = new ModuleService();
             var entity= service.GetModuleInfo(id);
             var v=service.Delete(entity);
             if (v)
             {
                 return Content("OK");
             }
             return Content("ERROR");
         }
    }
}
